home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine CD 1995 / Archive Magazine CD 1995.iso / discs / prog_disc / volume_7 / issue_09 / adv_basic / !PrintTest / !Help next >
Encoding:
Text File  |  1994-04-25  |  4.7 KB  |  65 lines

  1. Text Printing Via !Printers 
  2. ---------------------------
  3.  
  4. I have recently had an enquiry from Paul Pibworth about outputting text via the RISC OS printer drivers - which basically was how does one go about it? This is an important question as the latest RISC OS Style Guide states that all printed output must pass via the drivers and with the advent of the RiscPCs and RISC OS 3.5 it advisable to follow Acorn guidelines as closely as possible.
  5.  
  6. The theoretical advantage is that !Printers translates certain embedded codes (for bold, italic etc) to the correct ones for the printer in use meaning that a program can output the same codes whichever printer is attached. I say 'theoretical' because I haven't actually managed to make it work 100% yet!
  7.  
  8. Communicating with !Printers requires the use of the RISC OS message passing protocol which in turn means that the program must be running under the wimp. The procedure is as follows:
  9.  
  10. The application sends a Message_PrintSave (&80142). IF !Printers is loaded then !Printers sends a Message_PrintFile (&80140), else the Message_PrintSave 'bounces' (i.e. it is returned unanswered) and the application should complain that !Printers is not loaded. If !Printers is loaded it will send a Message_DataSaveAck (&2) which will contain a file name which can be used for data transfer. The application then writes the data and finishes by sending a Message_DataLoad (&3). Finally !Printers will send a Message_DataLoadAck (&4).
  11.  
  12. To try and keep things simple we'll only consider the case when Message_PrintSave is used to start a print job without dragging an icon - for example via a dialog box obtained by pressing <PRINT>. In the case where a file icon is dragged to the !Printers icon on the iconbar the code is exactly the same as that required to save to the Filer so we'll ignore this for now.
  13.  
  14. The example program on the monthly disk simply sends an ASCII file to !Printers when the iconbar icon is clicked on. Note however, that the full printing protocol is considerably more complicated than this example but it does work in the case of text files.
  15.  
  16. Having worked out how to send the file to !Printers all that remains is to embed the required control codes to turn bold on/off etc. It is possible to turn on bold printing for example by embedding the following codes in the text:
  17.  
  18. <27><%10000001>  (i.e. ASCII 27 followed by ASCII 129)
  19.  
  20. The bits that are set in the second byte determine whether the effect is on or off and have the following meanings:
  21.  
  22. bit 0 bold        on/off
  23.     1 light       on/off
  24.     2 italic      on/off
  25.     3 underline   on/off
  26.     4 superscript on/off
  27.     5 subscript   on/off
  28.     6 must be 0
  29.     7 must be 1
  30.  
  31. The section of code from the example program to demonstrate this is as follows:
  32.  
  33. file% = OPENOUT(name$)
  34. BPUT# file%,"This is a printer test file.."
  35. BPUT# file%,&0D
  36. BPUT# file%,27:BPUT# file%,%10000001
  37. BPUT# file%,"And now in bold (hopefully!)"
  38. BPUT# file%,27:BPUT# file%,%10000000
  39. BPUT# file%,"And now bold IS OFF)"
  40. cond$=CHR$&1F+"9201"                   :REM part of a FWP file! (probably won't
  41. BPUT# file%,cond$                      :REM work on printers other than a BJ10)
  42. BPUT# file%,"And now in CONDENSED HOPEFULLY!"
  43. BPUT# file%,27:BPUT# file%,%10000001   :REM Bold on
  44. BPUT# file%,"And now in condensed and ";
  45. BPUT# file%,27:BPUT# file%,%10001000   :REM Bold off, underline on
  46. BPUT# file%,"underlined";
  47. BPUT# file%,27:BPUT# file%,%10000000   :REM all effects off
  48. BPUT# file%," (hopefully!)"
  49. CLOSE# file%
  50.  
  51. Unfortunately the range of effects that can be produced in this manner is very limited and does not include condensed printing which can be handy. It should be possible to place any control code sequence in the file by embedding the following codes:
  52.  
  53. <27><%11000000>
  54. <printer specific codes..>
  55. <27><0>
  56.  
  57. These codes will be sent directly to the printer without being translated by the driver, but this means of course that your program will need to allow the user to input the correct codes for their particular printer (not the ideal solution!). Further details of the 'Fancy Text' format as it is known can be found in the RISC OS 3 User Guide, page 247.
  58.  
  59. As can be seen from the above code condensed printing has been turned on in a non-Acorn approved manner because the <27><%11000000> sequence appears to have no effect on my system. If anyone can tell me what is going on I would be very grateful!
  60.  
  61. While on the subject of printing does anyone have routines to detect whether a printer driver is loaded and whether the printer is online (various routines have been published in the past but I have yet to find one that works correctly when a Turbo Driver is in use).
  62.  
  63. Any questions or comments about Basic programming would be gratefully received, please write to Paul Hobbs, Rheinpfalzstrasse 2, 85049 Ingolstadt, Germany.
  64.  
  65.